package com.example.leetdemo.plan1;

import java.util.Vector;

public class Sword040 {

    public int maximalRectangle(String[] matrix) {
        int[][] key_1_arr = new int[matrix.length][matrix[0].length()];
        for (int i = 0; i < matrix.length; i++) {
            int key1 = 0;
            for (int j = 0; j < matrix[i].length(); j++) {
                if (matrix[i].charAt(j) == '1') {
                    key1++;
                } else {
                    key1 = 0;
                }
                key_1_arr[i][j] = key1;
            }
        }
        int max = -1;
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length(); j++) {
                if (matrix[i].charAt(i) == '0') {
                     continue;
                }
                int calculator = calculatorMax(i, j, key_1_arr);
                max = Math.max(calculator, max);
            }
        }
        return max;
    }

    private int calculatorMax(int p, int q, int[][] key) {
        int t1 = key[p][q], min = key[p][q];
        for (int i = p - 1; i >= 0; i--) {
            if (key[i][q] == 0) {
                break;
            }
            min = Math.min(min, key[i][q]);
            t1 = Math.max(min * (p - i + 1), t1);
        }
        return t1;
    }

    public static void main(String[] args) {
        Sword040 sword040 = new Sword040();
        System.err.println(sword040.maximalRectangle(new  String[] {
                "10100","10111","11111","10010"
        }));
    }

    private void test() {
        int col = 2;

    }
}
